package
{
	import flash.display.Sprite;

	public class Drone implements IFGFighter
	{
		private var xVel:int;
		private var yVel:int;
		private var weapon:IFGWeapon;
		private var s:Sprite;
		private static var TYPE:int = 2;
		private static var HEIGHT:int = 18;
		private static var WIDTH:int = 24;
		private static var COLOR:uint = 0x00FF00;
		
		private var shotFreq:int;
		private var xCycleLength:int;
		private var yCycleLength:int;
		private var turnCount:int;
		
		public function Drone(xPosition:int, yPosition:int, xVelocity:int, yVelocity:int, startWeapon:IFGWeapon, xCycle:int, yCycle:int, shotFrequency:int)
		{
			xVel = xVelocity;
			yVel = yVelocity;
			this.weapon = startWeapon;
			s = new Sprite();
			s.graphics.beginFill(COLOR);
			s.graphics.drawRect(xPosition, yPosition, WIDTH, HEIGHT);
			turnCount = 0;
			xCycleLength = xCycle;
			yCycleLength = yCycle;
			shotFreq = shotFrequency;
		}
		
		public function shoot():IFGPiece 
		{
			return weapon.shoot(s.x, s.y, s.width, TYPE);
		}
		
		public function destroy():void 
		{
			
		}
		
		public function getXPos():int {
			return s.x;
		}
		
		public function getYPos():int {
			return s.y;
		}

		public function setXVel(xVelocity:int):void
		{
			xVel = xVelocity;
		}
		
		public function setYVel(yVelocity:int):void
		{
			yVel = yVelocity;
		}
		
		public function getXVel():int {
			return xVel;
		}
		
		public function getYVel():int {
			return yVel;
		}
		
		public function getHeight():int {
			return s.height;
		}
		
		public function getWidth():int {
			return s.width;
		}
		
		public function getColor():uint {
			return COLOR;
		}
		
		public function getSprite():Sprite {
			return s;
		}
		
		public function move():void
		{
			s.x += xVel;
			s.y += yVel;
			turnCount++;
			if (turnCount%xCycleLength == 0) {
				xVel = -xVel;
			}
			if (turnCount%yCycleLength == 0) {
				yVel = -yVel;
			}
			if (turnCount%shotFreq == 0) {
				shoot();
			}
		}
		
		public function getType():int
		{
			return TYPE;
		}
		
	}
}